package kxfang.com.user.acitvity.set;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ToastUtils;

import kxfang.com.base.activity.MvvmBaseActivity;
import kxfang.com.base.utils.GsonUtils;
import kxfang.com.base.viewmodel.IMvvmBaseViewModel;
import kxfang.com.common.config.HttpConfig;
import kxfang.com.common.utils.HawkUtil;
import kxfang.com.common.utils.MyUtils;
import kxfang.com.common.utils.StatusBarUtil;
import kxfang.com.http.EasyHttp;
import kxfang.com.http.callback.SimpleCallBack;
import kxfang.com.http.exception.ApiException;
import kxfang.com.user.R;
import kxfang.com.user.databinding.UserActivityFeedbackBinding;
import kxfang.com.user.parameter.FeedPar;


public class FeedBackActivity extends MvvmBaseActivity<UserActivityFeedbackBinding, IMvvmBaseViewModel> {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setTopActivityView(this, viewDataBinding.topView);
        initView();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    protected IMvvmBaseViewModel getViewModel() {
        return null;
    }

    @Override
    protected int getBindingVariable() {
        return 0;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.user_activity_feedback;
    }

    @Override
    protected void onRetryBtnClick() {

    }

    private void initView() {
        viewDataBinding.activityBack.setOnClickListener(view -> finish());
        viewDataBinding.evaluationButton.setOnClickListener(v -> {
            loadData();
        });
    }

    private void loadData() {
        MyUtils.loadingDialog(this,"反馈中···");
        FeedPar par = new FeedPar();
        par.setAdvise(viewDataBinding.editFeed.getText().toString());
        if (HawkUtil.getUserId() != null) {
            par.setUserID(HawkUtil.getUserId());
        } else {
            MyUtils.myShowDialog(this);
            return;
        }
        EasyHttp.post(HttpConfig.addFeed)
                .cacheKey(HttpConfig.addFeed)
                .upJson(GsonUtils.toJson(par))
                .execute(new SimpleCallBack<Boolean>() {
                    @Override
                    public void onSuccess(Boolean msgModel) {
                        ToastUtils.showShort("反馈成功");
                        viewDataBinding.editFeed.setText("");
                        finish();
                    }

                    @Override
                    public void onError(ApiException e) {
                        MyUtils.disLoading();
                    }

                    @Override
                    public void onCompleted() {
                        MyUtils.disLoading();
                    }
                });

    }

}
